2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_POINTCOMPONENT_JUCEHEADER__
27 #define __JUCER_POINTCOMPONENT_JUCEHEADER__
29 #include "jucer_ElementSiblingComponent.h"
30 #include "../../ui/jucer_PaintRoutineEditor.h"
33 //==============================================================================
36 class PointComponent
: public ElementSiblingComponent
39 //==============================================================================
40 PointComponent (PaintElement
* const owner_
)
41 : ElementSiblingComponent (owner_
)
44 setMouseCursor (MouseCursor::UpDownLeftRightResizeCursor
);
51 virtual const RelativePositionedRectangle
getPosition() = 0;
52 virtual void setPosition (const RelativePositionedRectangle
& newPos
) = 0;
54 virtual void updatePosition()
56 if (dynamic_cast <PaintRoutineEditor
*> (getParentComponent()) != 0)
58 const Rectangle
<int> area (((PaintRoutineEditor
*) getParentComponent())->getComponentArea());
60 const Rectangle
<int> r (getPosition().getRectangle (area
, owner
->getDocument()->getComponentLayout()));
62 setCentrePosition (r
.getX(), r
.getY());
66 //==============================================================================
67 void paint (Graphics
& g
)
69 g
.setColour (Colours::white
);
70 g
.drawEllipse (2.0f
, 2.0f
, getWidth() - 4.0f
, getHeight() - 4.0f
, 2.0f
);
72 g
.setColour (Colours::black
);
73 g
.drawEllipse (1.0f
, 1.0f
, getWidth() - 2.0f
, getHeight() - 2.0f
, 2.0f
);
76 //==============================================================================
77 void mouseDown (const MouseEvent
& e
)
79 const Rectangle
<int> area (((PaintRoutineEditor
*) getParentComponent())->getComponentArea());
80 dragX
= getX() + getWidth() / 2 - area
.getX();
81 dragY
= getY() + getHeight() / 2 - area
.getY();
84 void mouseDrag (const MouseEvent
& e
)
86 const Rectangle
<int> area (((PaintRoutineEditor
*) getParentComponent())->getComponentArea());
87 int x
= dragX
+ e
.getDistanceFromDragStartX();
88 int y
= dragY
+ e
.getDistanceFromDragStartY();
90 JucerDocument
* const document
= owner
->getDocument();
94 x
= document
->snapPosition (x
);
95 y
= document
->snapPosition (y
);
98 const RelativePositionedRectangle
original (getPosition());
99 RelativePositionedRectangle
pr (original
);
101 Rectangle
<int> r (pr
.getRectangle (Rectangle
<int> (0, 0, area
.getWidth(), area
.getHeight()),
102 document
->getComponentLayout()));
103 r
.setPosition (x
, y
);
105 pr
.updateFrom (r
.getX(), r
.getY(), r
.getWidth(), r
.getHeight(),
106 Rectangle
<int> (0, 0, area
.getWidth(), area
.getHeight()),
107 document
->getComponentLayout());
113 void mouseUp (const MouseEvent
& e
)
122 #endif // __JUCER_POINTCOMPONENT_JUCEHEADER__